Module Module_Recursive

    Public Function Count_Before(ByVal CHK_Date As String, ByVal User_ID As String) As Integer
        'Function for check before date
        Dim Ret As Integer
        If Chk_Active_Date(CHK_Date, User_ID) Then
            Ret = 1 + Count_Before(Decrease_Date(CHK_Date), User_ID)
        Else
            Ret = 0
        End If
        Return Ret

    End Function

    Public Function Count_After(ByVal CHK_Date As String, ByVal User_ID As String) As Integer
        'Function for check after date
        Dim Ret As Integer
        If Chk_Active_Date(CHK_Date, User_ID) Then
            Ret = 1 + Count_After(Increase_Date(CHK_Date), User_ID)
        Else
            Ret = 0
        End If
        Return Ret

    End Function


    Public Function Chk_Active_Date(ByVal CHK_Date As String, ByVal User_ID As String) As Boolean
        'Function for check ID use in CHK_Date
        Dim StrSql_CheckDate As String = " Select  Distinct  "
        Dim Ds_CheckDate As New DataSet
        Dim Wss As New Carres_Webservice.PTT_CARRESERVE_WEBSERVICE
        Wss.Url = iPAddressServerWebService & "PTT_CARRESERVE_WEBSERVICE.asmx"
        StrSql_CheckDate = StrSql_CheckDate & " SubString(StartDate,1,10) AS StartDate  From InvReserveInfo "
        StrSql_CheckDate = StrSql_CheckDate & " Where (SubString(StartDate,1,10) <= '" & CHK_Date & "') and (SubString(StopDate,1,10) >= '" & CHK_Date & "')"
        StrSql_CheckDate = StrSql_CheckDate & " AND (UserId = '" & User_ID & "') AND (UserStatus <> 'TO')"
        StrSql_CheckDate = StrSql_CheckDate & " AND (UserStatus <> 'UC') AND (UserStatus <> 'AN') AND (UserStatus <> 'BC')"
        Ds_CheckDate = Wss.WebCustomBindData(StrSql_CheckDate)
        If Not Ds_CheckDate Is Nothing Then
            Chk_Active_Date = True
        Else
            Chk_Active_Date = False
        End If

    End Function

    Public Function Increase_Date(ByVal CHK_Date As String) As String
        'Function for increase 1 day (+)
        Dim TmpChk_Date As Date = CDate(CHK_Date).AddDays(1)
        Increase_Date = Format(TmpChk_Date, "yyyy-MM-dd")
    End Function

    Public Function Decrease_Date(ByVal CHK_Date As String) As String
        'Function for decrease 1 day (-)
        Dim TmpChk_Date As Date = DateAdd("d", -1, CDate(CHK_Date))
        Decrease_Date = Format(TmpChk_Date, "yyyy-MM-dd")

    End Function

End Module
